/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MessageFrame.java
 *
 * Created on 13 Αυγ 2009, 2:44:47 μμ
 */

package gui;

import base.message.Data;
import base.message.Message;
import base.node.WSNode;
import java.util.Vector;
import routing.RouteNodeAbstraction;
import routing.RouteNodeList;
import simulation.SimulationManager;

/**
 *
 * @author Arvanitis Ioannis
 */
public class MessageFrame extends javax.swing.JFrame {

    /** Creates new form MessageFrame */
    public MessageFrame() {
        initComponents();
        setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextFieldSrcNode = new javax.swing.JTextField();
        jLabelSrcNode = new javax.swing.JLabel();
        jLabelDstNode = new javax.swing.JLabel();
        jTextFieldDstNode = new javax.swing.JTextField();
        jLabelTTL = new javax.swing.JLabel();
        jTextFieldTTL = new javax.swing.JTextField();
        jLabelData = new javax.swing.JLabel();
        jTextFieldData = new javax.swing.JTextField();
        jButtonSend = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Message Manager");

        jTextFieldSrcNode.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabelSrcNode.setText("Source Node :");

        jLabelDstNode.setText("Destination Node :");

        jTextFieldDstNode.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabelTTL.setText("TTL :");

        jTextFieldTTL.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextFieldTTL.setText("10");

        jLabelData.setText("Data :");

        jTextFieldData.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jButtonSend.setText("Send");
        jButtonSend.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSendActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelSrcNode)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldSrcNode, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelDstNode)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldDstNode, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelTTL)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldTTL, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelData)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldData, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButtonSend, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabelDstNode, jLabelSrcNode});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabelData, jLabelTTL});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabelSrcNode, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextFieldSrcNode, javax.swing.GroupLayout.Alignment.LEADING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabelDstNode, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextFieldDstNode, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabelTTL, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextFieldTTL, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelData)
                    .addComponent(jTextFieldData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButtonSend)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonSendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSendActionPerformed

        ////////EXAMPLE////////
        Vector<String> v = new Vector<String>();
        v.addElement(jTextFieldData.getText());
        Data data = new Data(20, v);
        RouteNodeList rnl = new RouteNodeList();
        rnl.updateRouteNodeList(new RouteNodeAbstraction(1, false, new RouteNodeList().updateRouteNodeList(new RouteNodeAbstraction(Integer.parseInt(jTextFieldDstNode.getText()), true, null))));
//        rnl.updateRouteNodeList(new RouteNodeAbstraction(2, false, new RouteNodeList().updateRouteNodeList(new RouteNodeAbstraction(Integer.parseInt(jTextFieldDstNode.getText()), true, null))));

        Message msg = new Message(Message.msgTypes.DUMMY_MESSAGE, 0, Integer.parseInt(jTextFieldTTL.getText()), data, rnl);
        WSNode n = SimulationManager.getNode(Integer.parseInt(jTextFieldSrcNode.getText())-1);
        n.send(msg, true);
        ////////EXAMPLE////////

        jTextFieldSrcNode.setText(null);
        jTextFieldDstNode.setText(null);
        jTextFieldData.setText(null);
        jTextFieldTTL.setText("10");
    }//GEN-LAST:event_jButtonSendActionPerformed

    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonSend;
    private javax.swing.JLabel jLabelData;
    private javax.swing.JLabel jLabelDstNode;
    private javax.swing.JLabel jLabelSrcNode;
    private javax.swing.JLabel jLabelTTL;
    private javax.swing.JTextField jTextFieldData;
    private javax.swing.JTextField jTextFieldDstNode;
    private javax.swing.JTextField jTextFieldSrcNode;
    private javax.swing.JTextField jTextFieldTTL;
    // End of variables declaration//GEN-END:variables

}
